<template>
    <div>
        <a href="/kfadd">康复理疗信息新增</a>
        <h1>康复理疗信息显示</h1>
        项目名称<input type="text" v-model="info.namess">
        <input type="button" value="查询" @click="getlist">
        <input type="button" value="批量启用" @click="xgzt(true)">
        <input type="button" value="批量禁用" @click="xgzt(false)">
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th><input type="checkbox" v-model="checked" @click="checkedAll"></th>
                    <th>Id</th>
                    <th>项目名称</th>
                    <th>项目编码</th>
                    <th>服务人数</th>
                    <th>服务时长</th>
                    <th>状态</th>
                    <th>康复分类</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in data.list">
                    <td><input type="checkbox" v-model="ids" :value="a.Id"></td>
                    <td>{{ a.Id }}</td>
                    <td>{{ a.Name }}</td>
                    <td>{{ a.Cord }}</td>
                    <td>{{ a.porpel }}</td>
                    <td>{{ a.Time }}</td>
                    <td>{{ a.State == true ? "启用" : "禁用" }}</td>
                    <td>{{ a.KFName }}</td>
                    <th><input type="button" value="删除" @click="del(a.Id)"></th>
                </tr>
            </tbody>

        </table>
        <span>共{{ data.totalcount }}条</span>
        <span>每页{{ info.pagesize }}条</span>
        <span>共 {{ info.pageindex }} / {{ data.totalpage }}页</span>
        <input type="button" value="首页" @click="gopage(1)">
        <input type="button" value="上一页" @click="gopage(info.pageindex - 1)">
        <input type="button" value="下一页" @click="gopage(info.pageindex + 1)">
        <input type="button" value="尾页" @click="gopage(data.totalpage)">
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import axios from 'axios';
const router = useRouter();
let info: any = reactive({
    namess: '',
    pageindex: 1,
    pagesize: 2
})

let checked: any = ref(false);
let ids: any = ref([]);

let data: any = reactive({
    list: [],
    totalcount: 0,
    totalpage: 0
});
onMounted(() => {
    getlist();

})
const getlist = () => {
    axios({
        url: '/api/User/GetKF',
        method: 'get',
        params: info
    })
        .then(res => {
            console.log(res);
            Object.assign(data, res.data)
        })
        .catch(err => {
            console.log(err);

        })
}
const show = () => {
    info.pageindex = 1;
    getlist();
}
const gopage = (num: any) => {
    if (num < 1) {
        info.pageindex = 1;
        return;
    }
    if (num > data.totalpage) {
        info.pageindex = data.totalpage;
        return;
    }
    info.pageindex = num;
    getlist();
}

const checkedAll = () => {
    checked.value = !checked.value
    if (checked.value == true) {
        ids.value = data.list.map((a: any) => {
            return a.Id
        });
    }
    else {
        ids.value = [];
    }
}

const xgzt = (state: any) => {
    axios({
        url: '/api/User/XG',
        method: 'get',
        params: {
            id: ids.value.toString(),
            state: state
        }
    })
        .then(res => {
            if (res.data > 0) {
                alert('修改状态成功')
                checked.value == false
                ids.value = [];
                getlist();
                return;
            }
            else {
                alert('修改状态失败')
                checked.value == false
                ids.value = [];
                return;
            }
        })
        .catch(err => {
            console.log(err);

        })
}
//删除
const del = (id: any) => {
    axios({
        url: '/api/User/Delete',
        method: 'delete',
        params: {
            id: id
        }
    })
        .then(res => {
            if (res.data > 0) {
                alert('删除成功')

                getlist();
                return;
            }
            else {
                alert('删除失败')
                return;
            }
        })
        .catch(err => {
            console.log(err);

        })
}
</script>

<style scoped></style>